<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>注册认证</title>
<link href="/SmartCommunity/css/wechat/main.css" rel="stylesheet">
<link href="/SmartCommunity/css/wechat/weui.css" rel="stylesheet" />
</head>
<body>
	<div class="SpecialTop">
	<a class="back" href="javascript:history.back();"></a>
	<div class="renzheng">注册认证</div>
	</div>

	<div class="weui_cells">
            <div class="weui_cell weui_cell_select weui_select_after">
                <div class="weui_cell_hd">
                    小区
                </div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="weui_select" name="select2">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="weui_cells weui_cells_form">
        <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">手机号</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" id="phone" type="tel" placeholder="请输入手机号"/>
                </div>
            </div>
        <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">验证码</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" id="verify" type="number" placeholder="请输入验证码"/>
                </div>
                <div class="weui_cell_ft">
                    <label class="get_valid" >获取验证码</label>
                </div>
         </div>
         </div>
         <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="javascript:check()" id="showTooltips">确定</a>
        </div>
        <div id="loadingToast" class="weui_loading_toast" style="display:none;">
        <div class="weui_mask_transparent"></div>
        <div class="weui_toast">
            <div class="weui_loading">
                <div class="weui_loading_leaf weui_loading_leaf_0"></div>
                <div class="weui_loading_leaf weui_loading_leaf_1"></div>
                <div class="weui_loading_leaf weui_loading_leaf_2"></div>
                <div class="weui_loading_leaf weui_loading_leaf_3"></div>
                <div class="weui_loading_leaf weui_loading_leaf_4"></div>
                <div class="weui_loading_leaf weui_loading_leaf_5"></div>
                <div class="weui_loading_leaf weui_loading_leaf_6"></div>
                <div class="weui_loading_leaf weui_loading_leaf_7"></div>
                <div class="weui_loading_leaf weui_loading_leaf_8"></div>
                <div class="weui_loading_leaf weui_loading_leaf_9"></div>
                <div class="weui_loading_leaf weui_loading_leaf_10"></div>
                <div class="weui_loading_leaf weui_loading_leaf_11"></div>
            </div>
            <p class="weui_toast_content">数据加载中</p>
        </div>
    </div>
          <div class="weui_toptips weui_warn js_tooltips" id="js_tooltips_com">未选择所在小区</div>
          <div class="weui_toptips weui_warn js_tooltips" id="js_tooltips_phone">输入的电话号码不合法</div>
          <div class="weui_toptips weui_warn js_tooltips" id="js_tooltips_verify">验证码不能为空</div>
<script src="/SmartCommunity/js/wechat/jquery-2.2.0.min.js" type="text/javascript"></script>
<script  type='text/javascript'> 
$.ajax({
	type: "POST",
	url: "/SmartCommunity/wechat/get_community_list",
	async:false,
	contentType: "application/json; charset=utf-8",
	success: function(data){	
		var arr=eval(data);
		for(var i=0;i<arr.length;i++){
			$(".weui_select").append("<option value=\'"+arr[i].id+"\'>"+arr[i].name+"</option>");
		}		
	},
	error: function(){
		alert("网络请求失败");	
	} 
}); 
$(".get_valid").click(function(){
	var community=$(".weui_select").val();
	var phone = $("#phone").val();
	var regu = /^[1][0-9][0-9]{9}$/;
	var re = new RegExp(regu);
	if(community==""){
		var $temp=$("#js_tooltips_com");
		$temp.show();
        setTimeout(function () {
            $temp.hide();
        }, 2000);
        return false;
	}
		if (!re.test(phone)) { 
			var $temp=$("#js_tooltips_phone");
			$temp.show();
	        setTimeout(function () {
	            $temp.hide();
	        }, 2000);
			$("#phone").focus();
			return false;
		}
		$.ajax({
			type: "POST",
			url: "/SmartCommunity/wechat/get_randCode",
			//contentType: "application/json; charset=utf-8",
			data:{phone:phone,community:community},
			success: function(data){	
				var arr=eval("("+data+")");
				if(arr.verify==1){
					$(".get_valid").unbind('click'); 
					get_verify(60);
				}
				else if(arr.verify==0){
					alert("请输入注册的手机号");
				}
				else alert("获取验证码失败");
			},
			error: function(){
				alert("网络请求失败");	
			} 
		}); 		
});

function get_verify(e){
	if(e==0){
		$(".get_valid").text("获取验证码");
		$(".get_valid").click(function(){
			var community=$(".weui_select").val();
			var phone = $("#phone").val();
			$.ajax({
				type: "POST",
				url: "/SmartCommunity/wechat/get_randCode",
				contentType: "application/json; charset=utf-8",
				data:{phone:phone,community:community},
				success: function(data){	
					var arr=eval("("+data+")");
					if(arr.verify==1){
						$(".get_valid").unbind('click'); 
						get_verify(60);
					}
					else if(arr.verify==0){
						alert("请输入注册的手机号");
					}
					else alert("获取验证码失败");
				},
				error: function(){
					alert("网络请求失败");	
				} 
			}); 
		});
		clearTimeout(f);
	}
	else{
		$(".get_valid").text("等待"+ e +"秒");
	e--;
	var f =setTimeout('get_verify('+e+')',1000);
	}
}

function check (){
	var phone = $("#phone").val();
	var community=$(".weui_select").val();
	var verify=$("#verify").val();
	if(verify==""){
		var $temp=$("#js_tooltips_verify");
		$temp.show();
        setTimeout(function () {
            $temp.hide();
        }, 2000);
		$("#verify").focus();
			return false;
	}
	$('#loadingToast').show();
	$.ajax({
		type: "POST",
		url:"/SmartCommunity/wechat/reg",
		//dataType: 'json',
		//contentType: "application/json; charset=utf-8",
		data:{phone:phone,randCode:verify,community:community},
		success: function(msg) {
			msg=eval("("+msg+")");
			if(msg.response==0){
				$('#loadingToast').hide();
				alert("验证码输入错误！")
			}
			else if(msg.response==-1)
			{
				$('#loadingToast').hide();
				alert("认证失败，请重新认证！")
			}
			else{
				$('#loadingToast').hide();
				window.location.href="/SmartCommunity/views/wechat/register-success.html";
			}
		},
		error: function(error){
			alert("网络请求失败");
		}  
	});
}
</script>   
</body>